using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace Skywave.Security
{
    public class RijndaelStatic
    {
        private RijndaelManaged RMCrypto;
        public RijndaelStatic()
        {
            RMCrypto = new RijndaelManaged();
        }
        public RijndaelStatic(byte[] IV, byte[] Key)
        {
            RMCrypto = new RijndaelManaged();
            RMCrypto.IV = IV;
            RMCrypto.Key = Key;
        }
        public string Encrypt(string input)
        {
            byte[] inputBuffer, outputBuffer;
            inputBuffer = Encoding.Unicode.GetBytes(input);
            outputBuffer = RMCrypto.CreateEncryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
            string r = ComponentModel.ByteArrayConverter.ToString(outputBuffer);
            return r;
        }
        public string Decrypt(string input)
        {
            byte[] inputBuffer, outputBuffer;
            inputBuffer = ComponentModel.ByteArrayConverter.FromString(input);
            outputBuffer = RMCrypto.CreateDecryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
            string r = Encoding.Unicode.GetString(outputBuffer);
            return r;
        }
    }
}
